package approve.action;

import java.util.List;

import nguyen.dao.ReceiverDocumentDAO;

import model.pojo.Document;
import model.pojo.Employee;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class Re_MeetingDocumentPendding extends Activity{
	String database = "admin";
	Bundle language=null;
	String lang = "EN";
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
			lang=extras.getString("lang");
			language=extras.getBundle(lang);
		}
		return database;
	}
	Employee emp=null;
	
	ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);        
	        setContentView(R.layout.re_meetingdocumentpending);  
	        getDatabase();
	        
	        emp=(Employee) getIntent().getExtras().get("em");
	        List<Document> listDocs=getListMeetingDocumentPending();
	        if(language!=null){
	        	TextView la_headerTitle=(TextView)findViewById(R.id.la_headerTitle);
	        	la_headerTitle.setText(language.getString("metting_pending")+" ("+listDocs.size()+"):");
	        }
	        //System.out.println("meetingdoc: "+(listDocs.size()>0));
	        if(listDocs.size()>0){
	        	listView=(ListView) findViewById(R.id.meetingpendingdocumentlist);
		        listView.setAdapter(new ArrayAdapter<Document>(this, android.R.layout.simple_list_item_1,listDocs));
		        listView.setOnItemClickListener(viewDocument);
	        }else{
	        	TextView empltyList=(TextView) findViewById(R.id.empltyList);
				if(language!=null){
					empltyList.setText(language.getString("no_data"));
			}
	        }
	        
    }
	
	private OnItemClickListener viewDocument=new OnItemClickListener() {


		public void onItemClick(AdapterView<?> listDoc, View arg1, int arg2,
				long arg3) {
			Document doc=(Document) listDoc.getItemAtPosition(arg2);
			
			Intent intent=new Intent(Re_MeetingDocumentPendding.this,Re_ViewForm11.class);
			intent.putExtra("doc", doc);
			intent.putExtras(getIntent().getExtras());
			startActivityForResult(intent, 0);			
			
		}
		
	};
	
	private List<Document> getListMeetingDocumentPending(){
		return ReceiverDocumentDAO.getMeetingPendingDocument(emp.getIdemployee(), database,lang);
	}
//	private List<Document> getListMeetingDocumentPending(){
//		String sql="SELECT approvedoc.* FROM approvedoc,listapprove WHERE listapprove.IDEmployee='1322887525530'" +
//					" AND listapprove.IDGroupApprove = approvedoc.IDGroupApprove AND listapprove.IDStatus=2 " +
//								"AND approvedoc.IDStatus=2 And IDTypeDoc = 11";
//		String host="14.63.219.99";
//		String database="elihan";
//		String url="jdbc:mysql://"+host+":3306/"+database;
//		String user="erp";
//		String password="nguyen";
//		
//		Connection con=null;
//		
//		List<Document> list=new ArrayList<Document>();
//		try {
//			DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
//			con=(Connection) DriverManager.getConnection(url, user, password);
//			Statement statement= (Statement) con.createStatement();
//			ResultSet rs= statement.executeQuery(sql);			
//			Document doc=null;
//			while(rs.next()){	
//				doc=new Document(rs.getInt("IDApproveDoc"),rs.getString("Tile"),rs.getString("Description"),rs.getString("Content"));
//				list.add(doc);
//		
//			}
//		} catch (SQLException e) {	
//			openDialog();
//			System.out.println("ERROR CONNECT");
//			e.printStackTrace();
//		}
//		finally{
//			try {
//				con.close();
//			} catch (SQLException e) {
//				e.printStackTrace();
//			}
//		}
//		return list;
//	
//	}

	private void openDialog() {
		// TODO Auto-generated method stub
		
	}

}
